{extend name="base:base-add" /}
{block name="title"}
<title>添加分类</title>
{/block}
{block name="form"}
<form class="form form-horizontal" id="form-article-add">
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属分类：</label>
        <div class="form-controls col-xs-8 col-sm-4">
            <div class="form-controls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select name="parent_id" class="select">
                        {notempty name="to_level"}
                        {if ($data.parent_id == 0)}<option value="0" selected="selected">|-一级分类</option>{/if}
                        {volist name="to_level" id="vo"}
                        <option value="{$vo.id}" {if condition="$vo.id == $data.parent_id"} selected="selected" {/if}>|-{$vo.delimiter}{$vo.name}</option>
                        {/volist}
                        {else /}
                        <!--<option value="0">根分类</option>-->
                        {/notempty}
                </select>
                </span>
            </div>
        </div>
    </div>
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类名：</label>
        <div class="form-controls col-xs-8 col-sm-4">
            <input type="text" class="input-text" value="{$data.name}" placeholder="" id="name" name="name">
        </div>
    </div>
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2">url标识：</label>
        <div class="form-controls col-xs-8 col-sm-4">
            <input type="text" class="input-text" value="{$data.url_title}" placeholder="" id="url_title" name="url_title">
        </div>
    </div>
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2">SEO标题：</label>
        <div class="form-controls col-xs-8 col-sm-4">
            <input type="text" class="input-text" value="{$data.title}" placeholder="" id="title" name="title">
        </div>
    </div>
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2">关键词：</label>
        <div class="form-controls col-xs-8 col-sm-4">
            <input type="text" class="input-text" value="{$data.keywords}" placeholder="" id="keywords" name="keywords">
        </div>
    </div>
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2">排序：</label>
        <div class="form-controls col-xs-8 col-sm-1">
            <input type="text" class="input-text" value="{$data.listorder}" placeholder="" id="listorder"
                   name="listorder">
        </div>
    </div>
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2">状态：</label>
        <div class="form-controls col-xs-8 col-sm-4">
            <div class="radio-box">
                <input name="status" type="radio" id="1" value="1" {if condition="$data.status == 1" } checked {/if}>
                <label>正常</label>
            </div>
            <div class="radio-box">
                <input type="radio" id="2" name="status" value="2" {if condition="$data.status == 2" } checked {/if}>
                <label>禁用</label>
            </div>
        </div>
    </div>
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2">描述：</label>
        <div class="form-controls col-xs-8 col-sm-9">
            <textarea name="description" cols="" rows="" class="textarea" placeholder="说点什么...最少输入10个字符">{$data.description}</textarea>
            <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
        </div>
    </div>
    <input type="hidden" value="{$data.id}" name="id">
    <div class="row clearfix">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
            <button class="btn btn-secondary radius add" type="button"><i class="Hui-iconfont">&#xe632;</i>
                保存
            </button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
    $(".add").click(function () {
        var postData = {};
        var data = $("form").serializeArray();
        $.each(data, function () {
            postData[this.name] = this.value
        });
        $.ajax({
            url: "/{$backendPrefix}/article/category/edit/{$data.id}.html",
            type: "post",
            data: postData,
            "success": function (result) {
                var msgData = JSON.parse(result);
                if (msgData.status === true) {
                    layer.msg(msgData.message, {icon: 1, time: 1000}, function () {
                        window.parent.location.href = msgData.url
                    })
                } else {
                    layer.msg(msgData.message, {icon: 5, time: 2000})
                }
            }
        }, JSON);
    });
</script>
{/block}